<!doctype html>
<html lang="en">

<head>
	<title>鑫洋泉运营管理平台</title>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<!-- VENDOR CSS -->
	<link rel="stylesheet" href="../assets/vendor/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="../assets/vendor/font-awesome/css/font-awesome.min.css">
	<link rel="stylesheet" href="../assets/vendor/dataTables/jquery.dataTables.min.css">
	<link rel="stylesheet" href="../assets/vendor/linearicons/style.css">
	<!-- MAIN CSS -->
	<link rel="stylesheet" href="../assets/css/main.css">
	<!-- FOR DEMO PURPOSES ONLY. You should remove this in your project -->
	<link rel="stylesheet" href="../assets/css/demo.css">
	<link rel="stylesheet" href="../assets/css/sweetalert.css">
	<!-- GOOGLE FONTS -->
	<!-- <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700" rel="stylesheet"> -->
	<!-- ICONS -->
	<link rel="apple-touch-icon" sizes="76x76" href="../assets/img/apple-icon.png">
	<link rel="icon" type="image/png" sizes="96x96" href="../assets/img/favicon.png">
</head>

<body>
	<!-- WRAPPER -->
	<div id="wrapper">
		<!-- NAVBAR -->
		<nav class="navbar navbar-default navbar-fixed-top">
			<h1 class="header_1">
				 鑫洋泉运营管理系统 
			</h1>
		</nav>
		<!-- END NAVBAR -->
		<!-- LEFT SIDEBAR -->
		<div id="sidebar-nav" class="sidebar">
			<div class="sidebar-scroll">
				<nav>
					<ul class="nav">
						<li><a href="index.html" class="active"><i class="lnr lnr-home"></i> <span>首页</span></a></li>
						<li><a href="device.html" class=""><i class="lnr lnr-chart-bars"></i> <span>车辆信息</span></a></li>
                        <li><a href="custom.html" class=""><i class="lnr lnr-chart-bars"></i> <span>客户信息</span></a></li>
                         
                        <li>
                            <a href="#"><i class="lnr lnr-chart-bars"></i> <span>SIM卡管理</span></a>
                            <ul class="nav">
                                <li><a href="cardsStatistics.html">统计信息</a></li>
                                <li><a href="cardsList.html">列表信息</a></li>
                            </ul>
                        </li>
						<li>
							<a href="config.html"><i class="lnr lnr-chart-bars"></i> <span>配置管理</span></a>
							<ul class="nav">
								<li><a href="config.html" class=""><span>默认配置列表</span></a></li>
								<li><a href="parameters.html?1" class=""><span>解码类型</span></a></li>
								<li><a href="parameters.html?2" class=""><span>主机盒界面</span></a></li>
								<li><a href="parameters.html?3" class=""><span>前景和前后视角</span></a></li>
								<li><a href="parameters.html?4" class=""><span>转向视角</span></a></li>
								<li><a href="parameters.html?5" class=""><span>轨迹线类型</span></a></li>
						
							</ul>
						</li><!--<li><a href="device_detail.html" class=""><i class="lnr lnr-cog"></i> <span>设备详情</span></a></li>-->
					</ul>
				</nav>
			</div>
		</div>
		<!-- END LEFT SIDEBAR -->
		<!-- MAIN -->
		<div class="main">
			<!-- MAIN CONTENT -->
			<div class="main-content">
				<div class="container-fluid">
					<!--<h3 class="page-title">Panels</h3>-->
					<div class="row" id="vehiclesList">
						<div class="col-md-12">
							<!-- PANEL HEADLINE -->
							<div class="panel panel-headline">
								<div class="panel-heading">
									<div class="col-md-11">
										<h3 class="panel-title">关联车辆信息：</h3>
									</div>
									<div id="deviceAdd" class="col-md-1">
										<span class="input-group-btn"><input type="button" onclick="showModal('vehicleC')" class="btn btn-primary" value="添加"></span>
									</div>									<!--<p class="panel-subtitle">Panel to display most important information</p>-->
								</div>
								<div class="panel-body">
									<div class="row">
										<table id="vehicle" class="col-md-12 display" cellspacing="0" width="100%">
											
										</table>
									</div>
								</div>
							</div>
							<!-- END PANEL HEADLINE -->
						</div>
					</div>
					<div class="row" id="vehiclesSimList">
						<div class="col-md-12">
							<!-- PANEL HEADLINE -->
							<div class="panel panel-headline">
								<div class="panel-heading">
									<div class="col-md-11">
										<h3 class="panel-title">关联车辆信息：</h3>
									</div>
									<div id="deviceAdd" class="col-md-1">
										<span class="input-group-btn"><input type="button" onclick="showModal('vehicleI')" class="btn btn-primary" value="添加"></span>
									</div>									<!--<p class="panel-subtitle">Panel to display most important information</p>-->
								</div>
								<div class="panel-body">
									<div class="row">
										<table id="vehicleSim" class="col-md-12 display" cellspacing="0" width="100%">
											
										</table>
									</div>
								</div>
							</div>
							<!-- END PANEL HEADLINE -->
						</div>
					</div>
					<div class="row" id="customersList">
						<div class="col-md-12">
							<!-- PANEL HEADLINE -->
							<div class="panel panel-headline">
								<div class="panel-heading">
									<div class="col-md-11">
										<h3 class="panel-title">关联客户信息：</h3>
									</div>
									<!--<p class="panel-subtitle">Panel to display most important information</p>-->
									<div id='customerAdd' class="col-md-1">
										<span class="input-group-btn"><input type="button" onclick="showModal('CustomerV')" class="btn btn-primary" value="添加"></span>
									</div>	
								</div>
								<div class="panel-body">
									<div class="row">
										<table id="customer" class="col-md-12 display" cellspacing="0" width="100%">
											
										</table>
									</div>
								</div>
							</div>
							<!-- END PANEL HEADLINE -->
						</div>
					</div>
					<div class="row" id="simsList">
						<div class="col-md-12">
							<!-- PANEL HEADLINE -->
							<div class="panel panel-headline">
								<div class="panel-heading">
									<div class="col-md-11">
										<h3 class="panel-title">关联sim卡信息：</h3>
									<!--<p class="panel-subtitle">Panel to display most important information</p>-->
									</div>
									<!--<p class="panel-subtitle">Panel to display most important information</p>-->
									<div id="cardAdd" class="col-md-1">
										<span class="input-group-btn"><input type="button" onclick="showModal('simV')" class="btn btn-primary" value="添加"></span>
									</div>
								</div>
								<div class="panel-body">
									<div class="row">
										<table id="simInfo" class="col-md-12 display" cellspacing="0" width="1500px">
											
										</table>
									</div>
								</div>
							</div>
							<!-- END PANEL HEADLINE -->
						</div>
					</div>
					<input id='deviceId' type="hidden">
					<input id='cardId' type="hidden">
					<input id='customerId' type="hidden">
					<input id='dataType' type='hidden'>
				</div>
			</div>
			<!-- END MAIN CONTENT -->
		</div>
		<div class="modal fade" id="vehicleC" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title" id="myModalLabel">客户信息</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form">
                            <div class="form-group">
                                <!--<label for="user_id" class="col-sm-3 control-label">类型</label>-->
								<div class="col-sm-4">
									<select id="vehicleCType" class="form-control">
										<option value="1">大驾号</option>
										<option value="2">车牌号</option>
									</select>
								</div>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="vehicleCValue" name="mobile" value=""
                                        placeholder="">
                                </div>
                            </div>
                            <div class="form-group">
								<div class="col-sm-2">
                                	<!--<label for="user_id" class="control-label">关系</label>-->
								</div>
                                <div class="col-sm-3">
									<input type="radio" name="vehicleCRelaType" id="" 
         								value="0" checked> 分享关系
                                </div>
								<div class="col-sm-3">
									<input type="radio" name="vehicleCRelaType" id="" 
         								value="1" > 绑定关系
                                </div>
                            </div>
                       
                            <input type="hidden" id="vid">
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" onClick="addVehicleC()">提交</button>
						
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
		<div class="modal fade" id="vehicleI" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title" id="myModalLabel">车信息</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form">
                            <div class="form-group">
                                <!--<label for="user_id" class="col-sm-3 control-label">类型</label>-->
								<div class="col-sm-4">
									<select id="vehicleIType" class="form-control">
										<option value="1">大驾号</option>
										<option value="2">车牌号</option>
									</select>
								</div>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="vehicleIValue" name="mobile" value=""
                                        placeholder="">
                                </div>
                            </div>
                            
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" onClick="addVehicleI()">提交</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
		<div class="modal fade" id="CustomerV" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title" id="myModalLabel">客户信息</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form">
                            <div class="form-group">
                                <label for="user_id" class="col-sm-3 control-label">手机号</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="customerVValue" name="mobile" value=""
                                        placeholder="">
                                </div>
                            </div>
							<div class="form-group">
                                <div class="col-sm-2">
                                </div>
                                <div class="col-sm-3">
									<input type="radio" name="customerVRelaType" 
         								value="0" checked> 分享关系
                                </div>
								<div class="col-sm-3">
									<input type="radio" name="customerVRelaType"  
         								value="1" checked> 绑定关系
                                </div>
                            </div>
                       
                            <input type="hidden" id="iccid">
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" onClick="addCustomerV()">提交</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
		<div class="modal fade" id="simV" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title" id="myModalLabel"></h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form">
                            <div class="form-group">
                                <label for="user_id" class="col-sm-3 control-label">iccid</label>

                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="simVValue" name="mobile" value=""
                                        placeholder="">
                                </div>
                            </div>
                       
                            <input type="hidden" id="cid">
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" onClick="addSimV()">提交</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
        <!-- /.modal -->

	</div>
	<!-- END WRAPPER -->
	<!-- Javascript -->
	<script src="../assets/vendor/jquery/jquery.min.js"></script>
	<script src="../assets/vendor/bootstrap/js/bootstrap.min.js"></script>
	<script src="../assets/vendor/jquery-slimscroll/jquery.slimscroll.min.js"></script>
	<script src="../assets/vendor/dataTables/jquery.dataTables.min.js"></script>
	<script src="../assets/scripts/klorofil-common.js"></script>
	<script src="../assets/vendor/sweetalert.min.js"></script>
	<script>
		//car -> car - card  or car - custom    can remove card and custom
		//card -> car -card    can remove car
		//custom -> car - custom   can remove car
		var basePath = "/oss-ws/ws/0.1/";
		var thisURL = document.URL;
		var args = thisURL.split('?');
		var getVal =args[1];
		var type1 = args[2];
		var type2 = args[3];
		// var ajax = '../ws/0.1/' + type1 + '/cvs?' + getVal; //?cid=1'
		var ajax = basePath + type1 + '/' + type2 + '?' + getVal; //?cid=1'
		// var ajax = '../ws/0.1/'+type+'/cvs?'+ getVal; //?cid=1'
	
		 var showModal = function (id) {
            $('#' + id).modal('show');
        }
		var hideModal = function () {
			$('.modal').modal('hide');
		}
		var cleanValue = function () {
			$('#vehicleCValue').val('');
			$('#vehicleIValue').val('');
			$('#customerVValue').val('');
			$('#simVValue').val('');
		}
		var addVehicleC = function () {
			var data = {};
			data.type = $('#vehicleCType').val();
			data.relaType = $("input[name='vehicleCRelaType']:checked").val();
			data.value = $('#vehicleCValue').val();
			data.cid = $('#cid').val();
			
			var url = "../ws/0.1/customer/vehicle";
			doAjax(data, url);
			cleanValue();
		}
		var addVehicleI = function () {
			var data = {};
			data.type = $('#vehicleIType').val();
			data.value = $('#vehicleIValue').val();
			data.iccid = $('#iccid').val();
			var url = "../ws/0.1/simInfo/vehicle";
			doAjax(data, url);
			cleanValue();
		}
		var addCustomerV = function () {
			var  data = {};
			data.relaType = $("input[name='customerVRelaType']:checked").val();
			data.value = $('#customerVValue').val();
			data.vid = $('#vid').val();
			var url = "../ws/0.1/vehicle/customer";
			doAjax(data, url);
			cleanValue();

		}
		var addSimV = function () {
			var data = {};
			data.iccid = $('#simVValue').val();
			data.vid = $('#vid').val();
			var url = "../ws/0.1/vehicle/sim";
			doAjax(data, url);
			cleanValue();
		}
		var doAjax = function (data, url) {
            $.ajax(
                {
                    url: url,
                    // url: "../ws/0.1/vehicle",
                    // data: data,
                    type: "post",
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify(data),
                    dataType: "json",
                    beforeSend:function()
                    {
                        $("#tip").html("<span style='color:blue'>正在处理...</span>");
                        return true;
                    },
                    success:function(data)
                    {
                // "url": "../ws/0.1/vehicle/datas",
                        if(data.code == 200)
                        {
                            // table.ajax.url("../ws/0.1/param/pd?paramType=" + type).load();
                            // $("#successMessage").html("修改成功");
							window.location.reload();

                            // table.ajax.url('../ws/0.1/vehicle/datas').load();
                        }
                        else
                        {
                            // $("#warningMessage").html(data.message);
							hideModal();
                            alert(data.message);
                        }
                        // $('#myModal').modal('hide');
                    },
                    error: function()
                    {
                        alert('请求出错');
                    },
                    complete: function()
                    {
                        // $('#acting_tips').hide();
                    }
                });
        }
		var deleteRow = function (data) {
			var url = '../ws/0.1/';
			var type = $('#dataType').val();
			switch(type) {
				case 'customerToVehicle':
					url += 'customer/vehicle?' + getVal + '&' + 'vid=' + data;
					break;
				case 'vehicleToCustomer':
					url += 'vehicle/customer?' + getVal + '&' + 'cid=' + data;
					break;
				case 'vehicleToSim':
					url += 'vehicle/sim?' + getVal + '&' + 'iccid=' + data;
					break;
				case 'simToVehicle':
					url += 'simInfo/vehicle?' + getVal + '&' + 'vid=' + data;
					break;
			}

			swal({
                title: "确定删除吗？",    
                type: "warning",   
                showCancelButton: true,    
                confirmButtonColor: "#DD6B55",
                cancelButtonText: "取消", 
                confirmButtonText: "确定！",    
                closeOnConfirm: false }, 
                function() { 
                window.location.href = thisURL;
                    $.ajax(
                        {
                            url: url,
                            // url: "../ws/0.1/vehicle",
                            // data: data,
                            type: "delete",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            beforeSend:function()
                            {
                                return true;
                            },
                            success:function(data)
                            {
                                if(data.code == 200)
                                {
                                    swal("删除！", "删除成功", "success"); 
									location.reload();
                                }
                                else
                                {
                                    sweetAlert("error", data.message,"error");
                                }
                            },
                            error: function()
                            {
                                sweetAlert("error", "请求出错","error");
                            },
                            complete: function()
                            {
                            }
                        });
                });
				// window.location.href = thisURL;

		}
		var hiddenList = function (id) {
			$(id).hide();
		}
		var showVehicle = function (data) {
			$('#vehicle').dataTable( {
				"data": data,
				oLanguage: {
					"sUrl": "../assets/vendor/dataTables/zh_CN.json"
				},
				info: false,
				paging: false,
				//关闭行数选择
				"lengthChange": false,
				//关闭本地搜索
				"searching": false,
				"columnDefs": [
					{
						"targets": [0],
						"visible": false,
						"searchable": false
					}
				],

				"columns": [
					{
						"data": "vid",
						"title": ""
					}, {
						"data": "name",
						"title": "车名"
					}, {
						"data": "serial",
						"title": "设备编号"
					}, {
						"data": "plate",
						"title": "车牌"
					 }, {
						"data": "vin",
						"title": "大驾号"
					}, {
						"data": "ein",
						"title": "发动机编号"
					}, {
						"data": "created",
						"title": "创建日期"
					}, {
						"data": "relation",
						"title": "绑定关系"
					}, {
						"data": "bindTime",
						"title": "绑定时间"
					}, {
						"data": "vid",
						"title": "操作",
						render: function (data) {
							return "<a class='' href='#' onclick='deleteRow(" + data +")'>删除</a>";
                    	}
					}
				]
			});
			$('#vehiclesList').show();
		}

		var showCustom = function (data) {
			$('#customer').dataTable( {
				"data": data,
				oLanguage: {
					"sUrl": "../assets/vendor/dataTables/zh_CN.json"
				},
				info: false,
				paging: false,
				//关闭行数选择
				"lengthChange": false,
				//关闭本地搜索
				"searching": false,
				"columnDefs": [
					{
						"targets": [0],
						"visible": false,
						"searchable": false
					}
				],

				"columns": [
				 {
                    "data": "id",
                    "title": ""
                }, {
                    "data": "mobile",
                    "title": "手机号"
                }, {
                    "data": "nickName",
                    "title": "昵称"
                }, {
                    "data": "sex",
                    "title": "性别"
                },{
                    "data": "birthday",
                    "title": "生日"
                },{
                    "data": "created",
                    "title": "创建日期"
                },{
                    "data": "relation",
                    "title": "绑定关系"
                },{
                    "data": "bindTime",
                    "title": "绑定时间"
                },{
                    "data": "id",
                    "title": "操作",
					render: function (data) {
						return "<a class='' href='#' onclick='deleteRow(" + data + ")'>删除</a>"
					}
                }
            ]
			});
			$('#customersList').show();	
		}
		var showVehicleSim = function (data) {
			$('#vehicleSim').dataTable( {
				"data": data,
				oLanguage: {
					"sUrl": "../assets/vendor/dataTables/zh_CN.json"
				},
				info: false,
				paging: false,
				//关闭行数选择
				"lengthChange": false,
				//关闭本地搜索
				"searching": false,
				"columnDefs": [
					{
						"targets": [0],
						"visible": false,
						"searchable": false
					}
				],

				"columns": [
					{
						"data": "vid",
						"title": ""
					}, {
						"data": "name",
						"title": "车名"
					}, {
						"data": "serial",
						"title": "设备编号"
					}, {
						"data": "plate",
						"title": "车牌"
					 }, {
						"data": "vin",
						"title": "大驾号"
					}, {
						"data": "ein",
						"title": "发动机编号"
					}, {
						"data": "created",
						"title": "创建日期"
					}, {
						"data": "bindTime",
						"title": "绑定时间"
					}, {
						"data": "vid",
						"title": "操作",
						render: function (data) {
							return "<a class='' href='#' onclick='deleteRow(" + data +")'>删除</a>";
                    	}
					}
				]
			});
			$('#vehiclesSimList').show();
		}
		var showSim = function (data) {
			$('#simInfo').dataTable( {
				"data": data,
				"scrollX": true,
				oLanguage: {
					"sUrl": "../assets/vendor/dataTables/zh_CN.json"
				},
				info: false,
				paging: false,
				//关闭行数选择
				"lengthChange": false,
				//关闭本地搜索
				"searching": false,
				"columnDefs": [
					{
						"targets": [0],
						"visible": false,
						"searchable": false
					}
				],

				"columns": [
                {
                    "data": "userCode",
                    "title": '卡号'
                }, {
                    "data": "iccid",
                    "title": "iccid"
                }, {
                    "width": 40,
                    "data": "carStatus",
                    "title": "卡状态"
               /* }, {
                    "width": 40,
                    "data": "operator",
                    "title": "运营商"*/
                }, {
                    "width": 40,
                    "data": "flowOnline",
                    "title": "GPRS功能"
                }, {
                    "width": 40,
                    "data": "switchStatus",
                    "title": "设备状态"
                }, {
                    "width": 70,
                    "data": "GPRS",
                    "title": "GPRS状态"
                }, {
                    "width": 100,
                    "data": "userAff",
                    "title": "归属客户"
                }, {
                    "width": 40,
                    "data": "combo",
                    "title": "套餐类型"
                }, {
                    "width": 60,
                    "data": "flowSum",
                    "title": "流量总量(M)"
                }, {
                    "width": 60,
                    "data": "flowMoney",
                    "title": "流量花费(M)"
				}
            ]

			});
			$('#simsList').show();
		}
		hiddenList('#vehiclesList');
		hiddenList('#simsList');
		hiddenList('#customersList');
		hiddenList('#vehiclesSimList');
		$.get(ajax, function (data) {
			var dataType = data['type'];
			var data = data['data'];

			
			$('#dataType').val(dataType);
			switch(dataType){
				
				case 'vehicleToCustomer':
					showCustom(data);
					$('#customerAdd').show();
					$('#vid').val(getVal.split('=')[1]);
					break;
				case 'vehicleToSim':
					showSim(data);
					$('#cardAdd').show();
					$('#vid').val(getVal.split('=')[1]);
					break;
				case 'customerToVehicle':
					showVehicle(data);
					$('#cid').val(getVal.split('=')[1]);
					$('#deviceAdd').show();
					break;
				case 'simToVehicle':
					showVehicleSim(data);
					
					$('#iccid').val(getVal.split('=')[1]);
					$('#deviceAdd').show();
					break;
			}
			
			
		})
		
	</script>
</body>

</html>
